#include "ShakeAnimation.h"
#include "GraphicalElement.h"
#include <cmath>

ShakeAnimation::ShakeAnimation()
    : Animation(0), origo(0, 0), delta(0, 0), scale(1)
{
}

ShakeAnimation::~ShakeAnimation()
{
}

void ShakeAnimation::init()
{
    origo = element->getPosition();
}

void ShakeAnimation::update(double factor)
{
    int deltax = 4*sin(factor/1000)-10;
    int deltay = 5*cos(factor/700)-10;
    delta = Position(deltax, deltay);
    scale = 1.02;
}

void ShakeAnimation::render(const Position& parent)
{
    element->setPosition(origo+delta);
    element->getTexture()->setScale(scale);
    Animation::render(parent);
}

